import {Button, Drawer, message, Modal} from "antd";
import Chat from '@/pages/Chat'
import {useState} from "react";

type ChatModalProps = {
    callback?: (data: any) => void;
}

export const ChatModal: React.FC<ChatModalProps> = ({callback}) => {
    const [open, setOpen] = useState(false)
    const handleSubmit = (values: any) => {
        const error = values?.actions?.find((ret: any) => ret.type === 'error')

        if (error) {
            return message.error(error.message)
        }

        callback?.(values)
    }

    return <>
        <Button type="primary" onClick={() => setOpen(true)}>Chat</Button>
        <Drawer
            open={open}
            width={500}
            onClose={() => setOpen(false)}
            title="Chat"
            footer={null}
        >
            <Chat callback={handleSubmit} />
        </Drawer>
    </>


}
